package com.dzt.androidframework.network.mobapi.lottery;

import com.google.gson.GsonBuilder;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by M02323 on 2017/12/7.
 */

public class LotteryRetrofit {
	//服务器地址
	public static final String BASE_URL = "http://apicloud.mob.com/";
	private static LotteryRetrofit instance = null;

	private OkHttpClient client = new OkHttpClient();
	private GsonConverterFactory factory = GsonConverterFactory.create(new GsonBuilder().create());
	private Retrofit mRetrofit = null;

	public static LotteryRetrofit getInstance() {
		if (instance == null) {
			instance = new LotteryRetrofit();
		}
		return instance;
	}

	private LotteryRetrofit() {
		init();
	}

	private void init() {
		resetApp();
	}

	private void resetApp() {
		mRetrofit = new Retrofit.Builder()
				.baseUrl(BASE_URL)
				.client(client)
				.addConverterFactory(factory)
				.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
				.build();
	}

	public LotteryService getServer() {
		return mRetrofit.create(LotteryService.class);
	}
}
